# SSL验证问题
import socket
import re

img_url = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1203822861,3935498037&fm=26&gp=0.jpg"
# 建立连接
# client = socket.socket()
# client.connect(("ss2.bdstatic.com",443))

import ssl

client = ssl.wrap_socket(socket.socket())
client.connect(("ss2.bdstatic.com", 443))
# 构造报文
data = b"GET /70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1203822861,3935498037&fm=26&gp=0.jpg HTTP/1.1\r\nHost: ss2.bdstatic.com\r\n\r\n"
# 发送数据
client.send(data)
# 接收数据
ling1_data = client.recv(1024)
print(ling1_data)
changdu = int(re.findall(b"Content-Length: (.*?)\r\n", ling1_data)[0])
print(changdu)
tupianshuju = re.findall(b"\r\n\r\n(.*)", ling1_data, re.S)[0]
while True:
    tmp = client.recv(1024)
    print(tmp)
    tupianshuju += tmp
    if len(tupianshuju) >= changdu:
        break
# 断开
client.close()

with open("图片/ssl_g.jpg", "wb") as a:
    a.write(tupianshuju)
